
function cko_buff_query()
  local i
  local b = {}
  for k,v in cko_buff_translate do
    b[v] = 0
  end
  for i = 1,16 do
    local buff=UnitBuff("player",i)
    if buff then
       local idx = GetPlayerBuff(i-1,'HELPFUL|HARMFUL|PASSIVE')
       local time_left = GetPlayerBuffTimeLeft(idx)
       if time_left then
          if cko_buff_translate[buff] then
             b[cko_buff_translate[buff]]=time_left
          else
             message("Unknown buff: "..buff)
          end
       end
    end
  end
  return b
end


function cko_buff_antic()
  cko_print("buffing Antic")
end

-- make sure you're standing before you cast buffs

function cko_buff_elfinaria()
  local x = cko_buff_query()
  if x['Frost Armor'] < 15*60 then
    CastSpellByName("Frost Armor",1)
  end
  if x['Arcane Intellect'] < 20*60 then
    CastSpellByName("Arcane Intellect",1)
  end
  if x['Food'] < 2*60 then
    message("Eat food!")
  end
  if x['Regeneration'] < 2*60 then
    message("Use Troll's Blood Potion!")
  end
end

function cko_buff()
  local u = UnitName("player")
  if u=='Antic' then
    cko_buff_antic()
  end
  if u=='Elfinaria' then
    cko_buff_elfinaria()
  end
end

function cko_buff_macro()
  cko_macro_create('Buff',0,'/script cko_buff()')
end
